package cn.fl.capital.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.fl.export.condition.CapDailyRepaymentExportCondition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.capital.condition.CapDailyRepaymentQueryCondition;
import cn.fl.capital.service.ICapDailyRepaymentService;
import cn.fl.capital.vo.CapDailyRepaymentVO;
import cn.fl.customer.service.ICstBscInfoService;
import cn.fl.framework.base.context.CurrentThreadContext;

/**
 * @Description: 每日还款数据信息 控制层
 */
@Controller
@RequestMapping("/capital/capDailyRepayment")
public class CapDailyRepaymentController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(CapDailyRepaymentController.class);
	
	/**
	 * CapDailyRepayment 服务层BEAN
	 */
	@Autowired
	private ICapDailyRepaymentService capDailyRepaymentService;
	@Autowired
    private ICstBscInfoService cstBscInfoService;

	/**
	 * 到每日还款数据列表页面
	 */
	@RequestMapping(value = "/toDailyRepaymentPage.do", method = { RequestMethod.GET})
	public ModelAndView toDailyRepaymentPage(HttpServletRequest request, HttpServletResponse response) {
		BaseLogUtils.info(logger, "toListPage", "加载到每日还款数据列表页面.",CurrentThreadContext.getCurrentUserName());
		ModelAndView mav = new ModelAndView("capital/capDailyRepayment/capDailyRepayment");
		//事业部
		List<KeyValueVO> orgList = this.cstBscInfoService.searchBusinessOrgList();
		mav.addObject("buOrgCdList", JSON.toJSONString(orgList));
		return mav;
	}
	/**
	 * 初始化列表
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/initList.do", method = { RequestMethod.GET})
	@ResponseBody
	public Object initCapDailyRepaymentList(HttpServletRequest request, HttpServletResponse response) {
		String currentPage = request.getParameter("page");
		String pageSize = request.getParameter("pagesize");
		Pager page = new Pager();
		if (StringUtils.isNotEmpty(currentPage)) {
			page.setCurrentPage(Integer.parseInt(currentPage));
		}

		if (StringUtils.isNotEmpty(pageSize)) {
			page.setEveryPage(Integer.parseInt(pageSize));
		}
		String paySchId=request.getParameter("paySchId");
		String paySchNo=request.getParameter("paySchNo");
		String lsCntNo=request.getParameter("lsCntNo");//合同号
		String buOrgCd=request.getParameter("buOrgCd");//事业部
		String payDtMin=request.getParameter("payDtMin");//应付最小时间
		String payDtMax=request.getParameter("payDtMax");//应付最大时间
		String cstMgrNm=request.getParameter("cstMgrNm");//客户经理
		String cstNm=request.getParameter("cstNm");//客户名称
		CapDailyRepaymentQueryCondition condition=new CapDailyRepaymentQueryCondition();
		if(StringUtils.isNotEmpty(paySchId)){
			condition.setPaySchId(Long.valueOf(paySchId));
		}
		if(StringUtils.isNotEmpty(paySchNo)){
			condition.setPaySchNo(paySchNo.trim());
		}
		if(StringUtils.isNotEmpty(lsCntNo)){
			condition.setLsCntNo(lsCntNo.trim());
		}
		if(StringUtils.isNotEmpty(buOrgCd)){
			condition.setBuOrgCd(buOrgCd);
		}
		if(StringUtils.isNotEmpty(payDtMin)){
			condition.setPayDtMin( payDtMin);
		}
		if(StringUtils.isNotEmpty(payDtMax)){
			condition.setPayDtMax(payDtMax);
		}
		if(StringUtils.isNotEmpty(cstMgrNm)){
			condition.setCstMgrNm(cstMgrNm.trim());
		}
		if(StringUtils.isNotEmpty(cstNm)){
			condition.setCstNm(cstNm.trim());
		}
		page.setCondition(condition);
		BaseLogUtils.info(logger, "CapDailyRepaymentList", "初始化CapDailyRepayment列表页面数据.DATA:"+JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
		Pager pager = this.capDailyRepaymentService.searchListPage(page);
		List<CapDailyRepaymentVO> list = (List<CapDailyRepaymentVO>) pager.getResultList();
		ListPageVO<CapDailyRepaymentVO> listPage = new ListPageVO<CapDailyRepaymentVO>(list, pager.getTotalCount());
		return listPage;
	}

	   /****************************
     * 批量导出每日还款数据
     ****************************/
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/exportDailyRepaymentList.do", method = {RequestMethod.POST})
    @ResponseBody
    public DataResultVO exportDailyRepaymentList(HttpServletRequest request, HttpServletResponse response) {
        BaseLogUtils.info(logger,"exportDailyRepaymentList","批量导出每日还款数据==");
        CapDailyRepaymentExportCondition qc = new CapDailyRepaymentExportCondition();
        String lsCntNo=request.getParameter("lsCntNo");//合同号
		String buOrgCd=request.getParameter("buOrgCd");//事业部
		String payDtMin=request.getParameter("payDtMin");//应付最小时间
		String payDtMax=request.getParameter("payDtMax");//应付最大时间
		String cstMgrNm=request.getParameter("cstMgrNm");//客户经理
		String cstNm=request.getParameter("cstNm");//客户名称
		if(StringUtils.isNotBlank(lsCntNo)){
			qc.setLsCntNo(lsCntNo.trim());
		}
		if(StringUtils.isNotBlank(buOrgCd)){
			qc.setBuOrgCd(buOrgCd);
		}
		if(StringUtils.isNotBlank(payDtMin)){
			qc.setPayDtMin(payDtMin);
		}
		if(StringUtils.isNotBlank(payDtMax)){
			qc.setPayDtMax(payDtMax);
		}
		if(StringUtils.isNotEmpty(cstMgrNm)){
			qc.setCstMgrNm(cstMgrNm.trim());
		}
		if(StringUtils.isNotEmpty(cstNm)){
			qc.setCstNm(cstNm.trim());
		}
        return this.capDailyRepaymentService.exportRepaymentList(qc);
    }
}

